package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: DishController
 * Package: com.sky.controller.admin
 * Description:
 *
 * @Author JJQ
 * @create 2024/3/26 0026 23:05
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/dish")
@Api("菜品管理")
@Slf4j
public class DishController {
    private final DishService dishService;
    public DishController(DishService dishService){
        this.dishService = dishService;
    }

    @PostMapping
    @ApiOperation("新增菜品")
    public Result<String> save(@RequestBody DishDTO dishDTO) {
        dishService.saveWithFavor(dishDTO);
        return Result.success(MessageConstant.INSERT_SUCCESS);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result<String> update(@RequestBody DishDTO dishDTO) {
        dishService.updateWithFavor(dishDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售停售操作")
    public Result<String> startOrStop(@PathVariable Integer status, Long id) {
        dishService.startOrStop(status, id);
        return Result.success("操作成功");
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("删除菜品")
    public Result<String> delete(@PathVariable List<Long> ids) {
        dishService.deleteWithFavor(ids);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }

    @GetMapping("/{id}")
    @ApiOperation("菜品详情")
    public Result<DishVO> getById(@PathVariable Long id) {
        return Result.success(dishService.getById(id));
    }

    @GetMapping("/page")
    @ApiOperation("菜品分页")
    public Result<PageResult> page (DishPageQueryDTO queryDTO) {
        return Result.success(dishService.page(queryDTO));
    }

}
